<?php
/**
 * 智能名片
 */

namespace app\api\model;

use custom\Err;
use PDOStatement;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\Model;
use think\Exception;
use app\api\controller\Config;
use app\common\lib\RespCode;

class Customer extends Model
{
    const TYPE1 = 1; //不限
    const TYPE2 = 2;//只看小区
    const TYPE3 = 3;//只看商圈
    public static $type_s = [
        1 => '首次查看了你的名片，去跟他打个招呼以建立良好的形象',
        2 => '首次点赞了你的名片',
        3 => '名片视频播放',
        4 => '赞了你的动态',
        5 => '正在浏览你的推荐房源',
        6 => '关注了',
        7 => '分享房源',
        8 => "的费用情况，点击去计算",
        9 => '提交了贷款需求，点击查看',
        10 => '找房需求已更新，查看实时推荐房源',
        11 => '正在浏览你的房源',
        12 => '已帮填找房需求，查看实时推荐房源'
    ];

    /**
     * 名片个人信息
     */
    public function getCustomerList($params, $pageSize)
    {
        $where = " a.agent_id={$params['agent_id']} and a.user_id>0";
        if (isset($params['keywords']) && $params['keywords']) {
            $where .= " and (a.phone like '%{$params['keywords']}%' or a.remark like '%{$params['keywords']}%' or a.remark_phone like '%{$params['keywords']}%')";
        }
        //客户类型
        switch ($params['cus_type']) {
            case 1://潜在客户
                $where .= " and a.status=1";
                break;
            case 2://专属客户
                $where .= " and a.status=2";
                break;
            default:
                $where .= " and a.status=2";
        }
        //排序
        switch ($params['order_type']) {
            case 1://最后访问时间倒序
                $order = "a.last_time desc";
                break;
            case 2://互动次数倒序
                $order = "a.num desc";
                break;
            default:
                $order = "a.last_time desc";//默认最后访问时间
        }
        //有无手机号
        if (isset($params['is_phone']) && $params['is_phone']) {
            switch ($params['is_phone']) {
                case 1://有手机号
                    $where .= " and (a.phone <> '' or a.remark_phone<> '') ";
                    break;
                case 2://无手机号
                    $where .= " and a.phone = '' and a.remark_phone = ''";
                    break;
                default:
            }
        }

        //有无定制需求
        if (isset($params['is_demand']) && $params['is_demand']) {
            switch ($params['is_demand']) {
                case 1://有定制需求
                    $where .= " and a.is_demand=1";
                    break;
                case 2://无定制需求
                    $where .= " and a.is_demand=0";
                    break;
                default:
            }
        }

        //线索来源
        if (isset($params['source']) && $params['source']) {
            switch ($params['source']) {
                case 1://小程序分享
                    $where .= " and a.source=1";
                    break;
                case 2://文章获客
                    $where .= " and a.source=2";
                    break;
                default:
            }
        }

        $data = $this->getCustomer($where, $order, $params['page'], $pageSize);
        $count = db('company_agent_user')
            ->alias('a')
            ->join('erp_company_user b', 'a.user_id=b.id', 'left')
            ->where($where)
            ->count();
        $list['count'] = $count ?: 0;//数据总条数
        $list['page'] = $params['page'];//当前页码
        $list['pageSize'] = $pageSize;//每页显示条数
        $list['pageNum'] = ceil($list['count'] / $pageSize);//每页显示条数
        $list['list'] = $data ? $data : [];

        return $list;
    }

    public function getCustomer($where, $order, $page, $pageSize)
    {
        $field = "b.id user_id,b.nickname,b.cover,a.id agent_user_id,a.source,a.last_time,a.num,a.phone,a.remark_phone,a.remark,a.status,a.is_demand,a.recommend_house,a.source";
        //查询客户数据
        $data = db('company_agent_user')
            ->alias('a')
            ->field($field)
            ->join('erp_company_user b', 'a.user_id=b.id', 'left')
            ->page($page, $pageSize)
            ->where($where)
            ->order($order)
            ->select();


        //组装互动数据，根据数据
        foreach ($data as $key => $value) {
            //互动数据
            $re = db('agent_user_interaction_log')->where("agent_user_id={$value['agent_user_id']}")->order("itime desc")->find();
            //根据数据
            $follow = db('agent_follow_log')->where("agent_user_id={$value['agent_user_id']}")->order("itime desc")->find();
            $data[$key]['type'] = $re['type'] ? $re['type'] : 0;
            if ($value['status'] == 2) {
                //专属客户
                $desc = $re ? $this->getInteractionDesc($re['type'], $re['house_id'],$re['num']) : '';
            } else {
                //潜在客户
                $desc = $re ? Radar::interCusStyle($re['type'], $re['house_id']) : '';
            }
            $data[$key]['inter_desc'] = $desc;
            $data[$key]['house_id'] = $re['house_id'] ? $re['house_id'] : 0;
            $data[$key]['trends_id'] = $re['trends_id'] ? $re['house_id'] : 0;
            $data[$key]['last_time'] = date('Y-m-d H:i:s', $value['last_time']);
            $data[$key]['last_follow'] = $follow ? base64_decode($follow['remark']) : $desc;
            //推荐房源数量
            $data[$key]['house_count'] = $value['recommend_house'] ? count(explode(',', $value['recommend_house'])) : 0;
            $data[$key]['nickname'] = base64_decode($value['nickname']);

            $data[$key]['all_phone'] = $this->assemblyPhone($value);
            $data[$key]['check_phone']=$value['remark_phone']?$value['remark_phone']:$value['phone'];

        }

        return $data;
    }

    /**
     * 组装客户电话数据
     * @param array $data
     * @return array
     */
    public function assemblyPhone($data=[]){
        $res=[];
        if ($data['phone']&&$data['remark_phone']){
            $res=[$data['phone'],$data['remark_phone']];
        }
        if (!$data['phone']&&$data['remark_phone']){
            $res=[$data['remark_phone']];
        }
        if ($data['phone']&&!$data['remark_phone']){
            $res=[$data['phone']];
        }
        return $res;
    }

    public function getInteractionDesc($type, $house_id,$num=1)
    {

        switch ($type) {
            case 1:
                $desc = "首次查看了你的名片，去跟他打个招呼以建立良好的形象";
                if ($num>1){
                    $desc = "查看了你的名片，去跟他打个招呼以建立良好的形象";
                }
                break;
            case 2:
                $desc = "首次查看了你的名片，去跟他打个招呼以建立良好的形象";
                if ($num>1){
                    $desc = "查看了你的名片，去跟他打个招呼以建立良好的形象";
                }
                break;
            case 3:
                $desc = "名片视频播放";
                break;
            case 4:
                $desc = "赞了你的动态";
                break;
            case 5:
                $houseName = Radar::getHouseTitle($house_id);
                $desc = "正在浏览你的推荐房源" . $houseName;
                break;
            case 6:
                $houseName = Radar::getHouseTitle($house_id);
                $desc = "关注了" . $houseName;
                break;
            case 7:
                $houseName = Radar::getHouseTitle($house_id);
                $desc = "分享房源" . $houseName;
                break;
            case 8:
                $houseName = Radar::getHouseTitle($house_id);
                $desc = "询问了" . $houseName . "的费用情况，点击去计算";
                break;
            case 9:
                $desc = "提交了贷款需求，点击查看";
                break;
            case 10:
                $desc = "找房需求已更新，查看实时推荐房源";
                break;
            case 11:
                $houseName = Radar::getHouseTitle($house_id);
                $desc = "正在浏览你的房源" . $houseName;
                break;
            case 12:
                $desc = "帮填找房需求已更新，查看实时推荐房源";
                break;
            default:
                $desc = "";
        }

        return $desc;

    }

    /**
     * 客户信息
     * @param $params
     * @return mixed
     */
    public function getCustomerInfo($params)
    {
        $where = "a.id={$params['agent_user_id']}";
        //个人信息字段
        $field = "a.id agent_user_id,a.user_id,a.remark,a.status,a.company company_name,a.position,a.province,a.city,a.area,a.birthday,a.phone,a.is_demand,a.agent_id,a.remark_phone";
        $field .= ", d.nickname,d.cover";
        //定制需求字段
//        $field .= ",b.city_code,b.area_code,b.price_section,b.area_section,b.type,b.type_id,b.door_section";
        //贷款需求字段
        $field .= ",c.id loan_id,c.money,c.marriage_type,c.education_type,c.company loan_company_name,c.post,c.month_money,c.number,c.loan_money,c.balance_money,c.car_money,c.guarantee_money,c.nation,c.remark loan_remark";
        //查询数据
        $info = db('company_agent_user')
            ->alias('a')
            ->join('erp_company_user d', 'a.user_id=d.id', 'left')
//            ->join('erp_agent_user_demand b', 'd.id=b.user_id', 'left')
            ->join('erp_company_loan_consult c', 'd.id=c.user_id', 'left')
            ->field($field)
            ->where($where)
            ->find();
        $data = $this->getCustomerInfoStyle($info);

        return $data;
    }

    /**
     * 客户信息数据组装（个人信息，需求信息，贷款信息）
     * @param $data
     * @return mixed
     */
    public function getCustomerInfoStyle($data)
    {
        //客户个人信息
        $cust['agent_user_id'] = $data['agent_user_id'];//经纪人与用户关联主键id
        $cust['user_id'] = $data['user_id'];//用户id
        $cust['nickname'] = base64_decode($data['nickname']);//用户昵称
        $cust['remark'] = $data['remark'] ? $data['remark'] : '';//用户备注名
        $cust['status'] = $data['status'];//用户状态 0解绑客户、1潜在客户、2专属客户
        $cust['company_name'] = $data['company_name'] ? $data['company_name'] : '';//公司名称
        $cust['position'] = $data['position'] ? $data['position'] : '';//职位
        $cust['province'] = $data['province'] ? $data['province'] : '';//省份
        $cust['city'] = $data['city'] ? $data['city'] : '';//城市
        $cust['area'] = $data['area'] ? $data['area'] : '';//区/县
        $cust['birthday'] = $data['birthday'] ? date('Y-m-d', $data['birthday']) : '';//生日
        $cust['phone'] = $data['phone'] ? $data['phone'] : '';//电话
        $cust['remark_phone'] = $data['remark_phone'] ? $data['remark_phone'] : '';//备注电话
        $re['cust'] = $cust;

        //定制需求信息
        $demand=$this->getUserDmand($data['agent_id'],$data['user_id']);
        $re['demand'] = $demand;

        //贷款需求
        if (!$data['loan_id']) {
            $loan['money'] = '';//贷款金额
            $loan['marriage_type'] = '';//婚姻状况
            $loan['education_type'] = '';//学历状况
            $loan['loan_company_name'] = '';//工作单位
            $loan['post'] = '';//工作单位
            $loan['month_money'] = '';//月收入
            $loan['number'] = '';//当前房产套数
            $loan['loan_money'] = '';//住宅贷款
            $loan['balance_money'] = '';//消费款剩余金额
            $loan['car_money'] = '';//车款剩余金额
            $loan['guarantee_money'] = '';//担保金额
            $loan['nation'] = '';//民族
        } else {
            $loan['money'] = $data['money'] ? (string)($data['money'] / 100) : 0;//贷款金额
            $loan['marriage_type'] = $data['marriage_type'] ? self::getMarriageType($data['marriage_type']) : '未知';//婚姻状况
            $loan['education_type'] = $data['education_type'] ? self::getEducationType($data['education_type']) : '';//学历状况
            $loan['loan_company_name'] = $data['loan_company_name'] ? $data['loan_company_name'] : '';//工作单位
            $loan['post'] = $data['post'] ? $data['post'] : '';//工作单位
            $loan['month_money'] = $data['month_money'] ? (string)($data['month_money'] / 100) : 0;//月收入
            $loan['number'] = $data['number'] ? $data['number'] : 0;//当前房产套数
            $loan['loan_money'] = $data['loan_money'] ? (string)($data['loan_money'] / 100) : 0;//住宅贷款
            $loan['balance_money'] = $data['balance_money'] ? (string)($data['balance_money'] / 100) : 0;//消费款剩余金额
            $loan['car_money'] = $data['car_money'] ? (string)($data['car_money'] / 100) : 0;//车款剩余金额
            $loan['guarantee_money'] = $data['guarantee_money'] ? (string)($data['guarantee_money'] / 100) : 0;//担保金额
            $loan['nation'] = $data['nation'] ? $data['nation'] : '';//民族
        }


        $re['loan'] = $loan;
        return $re;

    }

    public function getUserDmand($agent_id = 0, $user_id = 0)
    {
        $res1 = db('agent_user_demand')->alias('b')->where("user_id={$user_id} and self_write=1")->find();
        $res2 = db('agent_user_demand')->alias('b')->where("user_id={$user_id} and agent_id={$agent_id} and self_write=0")->find();
        //定制需求：
        //自填时间   <  帮填时间  = 选帮填
        //自填时间   >=  帮填时间  = 选自填
        if (isset($res2['utime']) && ($res2['utime']> $res1['utime'])) {
            //2. 帮填时间 大于 自填时间  = 选帮填数据
            $data = $res2;
            $demand = self::getDemandInfo($data);
            return $demand;
        }
        $data = $res1;
        $demand = self::getDemandInfo($data);
        return $demand;
    }

    public function getDemandInfo($data)
    {
        $demand['city_name'] = $data['city_code'] ? self::getCityName($data['city_code'], 2) : '';//城市名;
        $demand['area_name'] = $data['area_code'] ? self::getCityName($data['area_code'], 3) : ['不限'];//区县名
        $demand['price_section'] = self::managerDemand($data['price_section'], 1);//价格区间
        $demand['area_section'] = self::managerDemand($data['area_section'], 2);//面积区间
        $demand['door_section'] = self::managerDemand($data['door_section'], 6);//户型
        $demand['village_name'] = '';//小区名称
        $demand['business_name'] = '';//商圈名称
        if ($data['type'] == self::TYPE2) {
            $name = HouseVillage::get_Name($data['type_id']);
            $demand['village_name'] = $name;
        }
        if ($data['type'] == self::TYPE3) {
            $name = BusinessArea::get_Name($data['type_id']);
            $demand['business_name'] = $name;
        }
        return $demand;
    }

    public static function managerDemand($data, $type)
    {
        if (!$data) {
            return [];
        } else {
            $all = explode(',', $data);
            foreach ($all as $key => $value) {
                $ps = explode('-', $value);
                $demand[$ps[0]] = $value ? IntervalConfig::getConfig_name($ps[0], $ps[1], $type) : '';//价格区间
            }
            ksort($demand);
            return array_values($demand);
        }
    }

    /**
     * 根据城市code获取城市名
     * @param $code
     * @return mixed
     */
    public static function getCityName($code='', $rank)
    {

        if ($rank == 2) {
            $name = db('region')->where("city_code in({$code}) and rank={$rank}")->value('name');
            return $name = $name ? $name : '';
        } else {
            if (empty($code)){
                $name['name']='不限';
            }else{
                $name = db('region')->where("city_code in({$code}) and rank={$rank}")->column('name');
            }
            return $name = $name ? $name : [];
        }


    }

    /**
     * 贷款信息婚姻状况
     * @param int $type
     * @return string
     */
    public static function getMarriageType($type = 0)
    {
        switch ($type) {
            case 0:
                $name = '未知';
                break;
            case 1:
                $name = '未婚';
                break;
            case 2:
                $name = '已婚';
                break;
            default:
                $name = '未知';
        }
        return $name;
    }

    /**
     * 贷款信息获取学历
     * @param int $type
     * @return string
     */
    public static function getEducationType($type = 1)
    {
        switch ($type) {
            case 1:
                $name = '中专或高中';
                break;
            case 2:
                $name = '大专';
                break;
            case 3:
                $name = '本科';
                break;
            case 4:
                $name = '研究生及以上';
                break;
            default:
                $name = '';
        }
        return $name;
    }

    /**
     * 客户基本信息保存
     * @param $params
     * @return int|string
     */
    public function saveCustomerInfo($params)
    {
        $up['company'] = isset($params['company_name'])?trim($params['company_name']):'';//公司名
        if (mb_strlen($up['company']) > 20) {
            Err::add('公司名称填写格式错误', RespCode::PARAMS_ERR);
            return false;
        }
        $up['position'] = isset($params['position'])?trim($params['position']):'';//职位
        if (mb_strlen($up['position']) > 10) {
            Err::add('职位名称填写格式错误', RespCode::PARAMS_ERR);
            return false;
        }
        $up['province'] = isset($params['province'])?trim($params['province']):'';//省
        $up['city'] = isset($params['city'])?trim($params['city']):'';//市
        $up['area'] = isset($params['area'])?trim($params['area']):'';//区/县
        $up['birthday'] = isset($params['birthday'])?strtotime($params['birthday']):'';//生日
        $up['remark'] = isset($params['remark'])?trim($params['remark']):'';//备注名
        if ($up['remark']&&mb_strlen($up['remark']) > 15) {
            Err::add('备注名填写格式错误', RespCode::PARAMS_ERR);
            return false;
        }
        $up['remark_phone'] = isset($params['remark_phone'])?trim($params['remark_phone']):'';//备注电话
        if($up['remark_phone']&&!preg_match("/^1[34578]\d{9}$/", $up['remark_phone'])){
            Err::add('备注电话填写格式错误', RespCode::PARAMS_ERR);
            return false;
        }
        $re = db('company_agent_user')->where("id={$params['agent_user_id']}")->update($up);
        if ($re !== false) {
            return true;
        } else {
            Err::add('保存失败', RespCode::QUERY_ERR);
            return false;
        }

    }

    /**
     * 互动记录
     * @param $params
     * @param $pageSize
     * @return mixed
     */
    public function getInteractionList($params, $pageSize)
    {
        $where = "agent_user_id={$params['agent_user_id']} and type in(1,2,4)";
        $data = db('agent_user_interaction_log')
            ->alias('a')
            ->field('a.id,a.type,a.house_id,a.itime,a.num')
            ->where($where)
            ->order("itime desc")
            ->select();
        foreach ($data as $key => $value) {
            $data[$key]['day_time'] = date('m-d', $value['itime']);
            $data[$key]['time'] = date('H:i', $value['itime']);
            $type_desc = $this->interStyle($value['type'], $value['house_id'],$value['num']);
            $data[$key]['type_desc'] = $type_desc;
        }
        $data = self::array_tree($data);
        $count = count($data);
        $page = (int)$params['page'];
        $pageSize = (int)$pageSize;
        $page_ = ($page - 1) * $pageSize;
        $data = array_slice($data, $page_, $pageSize);
        if ($pageSize > 0) {
            $pageNum = ceil($count / $pageSize);
        } else {
            $pageNum = 1;
        }
        $result['count'] = $count;
        $result['page'] = $page;
        $result['pageNum'] = $pageNum;
        $result['data'] = $data;
        return $result;
    }

    /**
     * 互动记录数据处理
     * @param $data
     * @return array
     */
    public static function array_tree($data)
    {
        $grouped = array();
        foreach ($data as $key => &$value) {
            $arr = [
                'time' => $value['time'],
                'type' => $value['type'],
                'house_id' => $value['house_id'],
                'type_desc' => $value['type_desc']
            ];
            $grouped[$value['day_time']]['day_time'] = $value['day_time'];
            $grouped[$value['day_time']]['children'][] = $arr;

        }

        return array_values($grouped);
    }

    /**
     * 房源互动记录
     * @param $params
     * @param $pageSize
     * @return mixed
     */
    public function getHouseInteractionList($params, $pageSize)
    {
        $where = "a.agent_user_id={$params['agent_user_id']} and a.type in(5,6,8,9,10,11,12)";
        $data = db('agent_user_interaction_log')
            ->alias('a')
            ->field('a.id,a.agent_user_id,a.type,a.house_id,a.itime,b.title,a.num')
            ->join('erp_house b', 'a.house_id=b.id', 'left')
            ->where($where)
            ->order("a.itime desc")
            ->select();

        foreach ($data as $key => $value) {
            $data[$key]['day_time'] = date('m-d', $value['itime']);
            $data[$key]['time'] = date('H:i', $value['itime']);
            $type_desc = $this->interStyle($value['type'], $value['house_id'],$value['num']);
            $data[$key]['type_desc'] = $type_desc;

        }
        $data = self::array_tree($data);
        $count = count($data);
        $page = (int)$params['page'];
        $pageSize = (int)$pageSize;
        $page_ = ($page - 1) * $pageSize;
        $data = array_slice($data, $page_, $pageSize);
        if ($pageSize > 0) {
            $pageNum = ceil($count / $pageSize);
        } else {
            $pageNum = 1;
        }
        $result['count'] = $count;
        $result['page'] = $page;
        $result['pageNum'] = $pageNum;
        $result['data'] = $data;
        return $result;
    }

    /**
     * 全国省
     * @return mixed
     */
    public function getProvince()
    {
        $data = db('region')->field('name')->where("rank=1")->order("initials asc")->select();
        return $data;
    }

    /**
     * 根据省查询市
     * @return mixed
     */
    public function getCity($params)
    {
        $params['name'] = trim($params['name']);
        if ($params['name'] == '澳门') {
            return [array('name' => '澳门')];
        } elseif ($params['name'] == '香港') {
            return [array('name' => '香港')];
        }
        $p_code = db('region')->where("name='{$params['name']}' and rank=1")->value('city_code');
        $data = db('region')->field('name')->where("rank=2 and p_code={$p_code}")->order("initials asc")->select();
        return $data;
    }

    /**
     * 根据市查询区/县
     * @return mixed
     */
    public function getArea($params)
    {
        $params['name'] = trim($params['name']);
        if ($params['name'] == '澳门' || $params['name'] == '香港') {
            $p_code = db('region')->where("name='{$params['name']}' and rank=1")->value('city_code');
        } else {
            $p_code = db('region')->where("name='{$params['name']}' and rank=2")->value('city_code');
        }
        $data = db('region')->field('name')->where("rank=3 and p_code={$p_code}")->order("initials asc")->select();
        return $data;
    }

    /**
     * 客户实时推荐房源列表
     * @param $params
     * @param $pageSize
     * @return mixed
     */
    public function getTimeRechouse($params, $pageSize)
    {
        $houres = db('company_agent_user')->where("id={$params['agent_user_id']}")->value('recommend_house');
        $houre_id = $houres ? $houres : 0;
        $where = "h.is_shelf=1 and h.deleted=0 and h.id in ({$houre_id})";
        $House = new House();
        $column = array_merge($House->houseFields, $House->villageFields, $House->typeFields, $House->auctionFields, $House->businessFields, $House->reginFields);

        $data = db('house')
            ->alias('h')
            ->field($column)
            ->join('erp_house_auction ha', 'h.auction_id = ha.id', 'LEFT')
            ->join('erp_house_type ht', 'h.house_type_id = ht.id', 'LEFT')
            ->join('erp_house_village hv', 'h.village_id = hv.id', 'LEFT')
            ->join('erp_business_area hb', 'h.business_area_id = hb.id', 'LEFT')
            ->join('erp_region hr', 'h.city_code = hr.city_code', 'LEFT')
            ->where($where)
            ->order('ha.auction_status asc,h.id desc')
            ->page($params['page'], $pageSize)
            ->select();
        $count = db('house')
            ->alias('h')
            ->join('erp_house_auction ha', 'h.auction_id = ha.id', 'LEFT')
            ->join('erp_house_type ht', 'h.house_type_id = ht.id', 'LEFT')
            ->join('erp_house_village hv', 'h.village_id = hv.id', 'LEFT')
            ->join('erp_business_area hb', 'h.business_area_id = hb.id', 'LEFT')
            ->join('erp_region hr', 'h.city_code = hr.city_code', 'LEFT')
            ->where($where)
            ->count();
        $data = House::house_list_style($data);
        $list['count'] = $count;//数据总条数
        $list['page'] = $params['page'];//当前页码
        $list['pageSize'] = $pageSize;//每页显示条数
        $list['pageNum'] = ceil($list['count'] / $pageSize);//每页显示条数
        $list['list'] = $data ? $data : [];//每页显示条数
        return $list;
    }


    /**
     * 互动/房源记录 显示处理
     * @param $type
     * @param $house_id
     * @param int $num
     * @return mixed|string
     */
    public function interStyle($type,$house_id,$num=1){
        $arr1=[1,2,3,4];
        $arr2=[5,6,7,8,11];
        $desc=Customer::$type_s[$type];
        if (in_array($type,$arr1)){
            if ($type==1){
                $type_desc= "<span style='color: #F8A31E'>{$desc}</span>";

            }else{
                $type_desc= "<span style='color: #000000'>{$desc}</span>";
            }
            if ($num>1&&in_array($type,[1,2])){
                $new_type_desc=str_replace('首次','第 '."<span style='color: #F8A31E'>{$num}</span>".' 次',$type_desc);
                $type_desc=$new_type_desc;
            }
        }else if (in_array($type,$arr2)){
            $houseName = Radar::getHouseTitle($house_id);
            if ($type == 8) {
                if ($num>1){
                    $str='第 '."<span style='color: #F8A31E'>{$num}</span>".' 次询问了';
                }else{
                    $str="询问了";
                }
                $type_desc = "<span style='color: #000000'>{$str}</span>"."<a style='color: #3693F2;text-decoration : none' href='".$house_id."'>{$houseName}</a>"."<a style='color: #000000'>的费用情况，点击去计算</a>";
            } else {
                $str='第 '."<span style='color: #F8A31E'>{$num}</span>".' 次';
                if ($num>1){
                    switch ($type){
                        case 5:
                            $desc=str_replace('正在',$str,$desc);
                        break;
                        case 6:
                            $desc=$str.$desc;
                        break;
                        case 11:
                            $desc=str_replace('正在',$str,$desc);
                         break;
                        default:
                        break;
                    }
                }
                $type_desc = "<span style='color: #000000'>{$desc}</span>"."<a style='color: #3693F2;text-decoration : none' href='".$house_id."'>{$houseName}</a>" ;
            }
        }else{
            $str='第 '."<span style='color: #F8A31E'>{$num}</span>".' 次';
            $desc=$str.$desc;
            $type_desc ="<span style='color: #000000'>{$desc}</span>";
        }
        return $type_desc;
    }
}
